package day06.work;

import java.util.Arrays;
import java.util.Scanner;

public class work {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        //1.定义方法:print
        //根据传入的参数打印指定行数的*
        System.out.print("请输入要打印*的行数：");
        int line = scanner.nextInt();
        print(line);

        //2.定义方法: PrimeNumber
        //传入两个数a和b,将a和b之间的质数输出
        System.out.println("判断质数");
        System.out.print("请输入一个整数:");
        int a = scanner.nextInt();
        System.out.print("请输入一个整数:");
        int b = scanner.nextInt();
        PrimeNumber(a,b);

        //3.定义方法:FindEqual
        //传入两个数组,找出两个数组中相同的元素
        int[] arr1 = {1,3,5,7,9,10};
        int[] arr2 = {0,2,4,7,9,10};
        int[] arr3 = new int[6];
        FindEqual(arr1,arr2,arr3);
        System.out.println("在两个数组中找相同的元素"+Arrays.toString(arr3));
    }
    public static void print(int a)
    {
        for(int i = 1;i<=a;i++)
        {
            for(int j = 0;j<i;j++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
    }
    public static void PrimeNumber(int a,int b)
    {
        assert(a>1 && b>1);
        //找出a和b中大的数
        int big = a>b? a:b;
        //找出a和b中小的数
        int small = a>b? b:a;
        //判断质数，只能被1和本身整除
        //产生small 到big中的数
        for(int i = small;i<=big;i++)
        {
            int j = 0;
            //判断素数
            for(j = 2;j<i;j++)
            {
                if(i % j == 0)
                {
                    break;
                }
            }
            if(i == j)
            {
                System.out.print(i+" ");
            }
        }
        System.out.println();
    }
    public static void FindEqual(int[] arr1,int[] arr2,int[] arr3)
    {
        //count记录arr3的下标
        int count = 0;
        //遍历数组 比较  相等的存到arr3中
        for(int i = 0;i<arr1.length;i++) {
            for (int j = 0; j < arr2.length; j++) {
                if (arr1[i] == arr2[j]) {
                    arr3[count] = arr1[i];
                    count++;
                }
            }
        }
    }
}
